#include "stopwords_removal.h"
#include "../../util.h"

StopwordsRemval::StopwordsRemval(iostream *model_file)
{
	string line;
	while(!model_file->eof())
	{
		getline(*model_file, line);
		stopword_list.insert(line);
	}
}

bool StopwordsRemval::is_stop(string word)
{
	if(word.length() == 1)
		return true;
	return stopword_list.find(word) != stopword_list.end();
}

string StopwordsRemval::remove(string query)
{
	string res;
	vector<string> &label_f = util::tokenize(query, " ");
	for(int i = 0; i < label_f.size(); ++ i){
		if(!is_stop(label_f[i])){
			res += label_f[i];
			res += " ";
		}
	}
	return res;
}
void StopwordsRemval::reform(QueryNode &node)
{
	node.label = remove(node.label);
}

QueryNode StopwordsRemval::reform_new(QueryNode &node)
{
	QueryNode res(remove(node.label));
	res.isVirtual = true;
	return res;
}